Use case: Starting the GFXTIM with watchdog timer ¶
This use case shows how to configure and start the watchdog counter and handle alarm and pre-alarm events.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
GFXTIM_HandleTypeDef hgfxtim = {
.Instance = GFXTIM;
.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
};
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim);
/* optional: if interrupt is enabled */
/* Registering the user callback function*/
HAL_GFXTIM_RegisterCallback(&hgfxtim,
HAL_GFXTIM_WDG_ALARM_CB_ID,
USER_GFXTIM_WDG_AlarmCallback);
HAL_GFXTIM_RegisterCallback(&hgfxtim,
HAL_GFXTIM_WDG_PRE_ALARM_CB_ID,
USER_GFXTIM_WDG_PreAlarmCallback);
/* Clock generator configuration */
GFXTIM_ClockGeneratorConfigTypeDef pClockGenConfig = {
.LCCHwReloadSrc = GFXTIM_LCC_HW_RELOAD_SRC_NONE;
.LCCReloadValue = 159999;
.LCCClockSrc = GFXTIM_LCC_CLK_SRC_SYSCLOCK;
.LineClockSrc = GFXTIM_LINE_CLK_SRC_FCC_UNDERFLOW;
.FCCHwReloadSrc = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
.FCCReloadValue = 0xFU;
.FCCClockSrc = GFXTIM_FRAME_CLK_SRC_LCC_UNDERFLOW;
.FrameClockSrc = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
.LineClockCalib = GFXTIM_LINE_CLK_CALIB_DISABLE;
.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
};
HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
&pClockGenConfig);
/* Watchdog timer configuration */
GFXTIM_WatchdogConfigTypeDef WdgConfig = {
.ClockSrc = GFXTIM_WATCHDOG_CLK_SRC_LINE_CLK;
.AutoReloadValue = 1000;
.PreAlarmValue = 500;
.AlarmInterrupt = GFXTIM_IT_ENABLE;
.PreAlarmInterrupt = GFXTIM_IT_ENABLE;
.HwReloadConfig = GFXTIM_WATCHDOG_HW_RELOAD_DISABLE;
};
HAL_GFXTIM_WatchdogTimer_Config(&hgfxtim, &WdgConfig);
/* Enable the watchdog timer */
HAL_GFXTIM_WatchdogTimer_Enable(&hgfxtim);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_IRQHandler(&hgfxtim);
/* Watchdog alarm callback function */
HAL_GFXTIM_WDG_AlarmCallback(&hgfxtim);
/* Watchdog pre alarm callback function */
HAL_GFXTIM_WDG_PreAlarmCallback(&hgfxtim);
/* optional */
/* Refresh the watchdog timer */
HAL_GFXTIM_WatchdogTimer_Refresh(&hgfxtim);
/* Disable the watchdog timer */
HAL_GFXTIM_WatchdogTimer_Disable(&hgfxtim);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
hal_gfxtim_handle_t hgfxtim;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_WDG_RegisterAlarmCallback(&hgfxtim,
USER_GFXTIM_WDG_AlarmCallback);
HAL_GFXTIM_WDG_RegisterPreAlarmCallback(&hgfxtim,
USER_GFXTIM_WDG_PreAlarmCallback);
/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_line_config_t p_line_config = {
.reload_src = HAL_GFXTIM_CLKGEN_LCNT_NO_RELOAD;
.reload_val = 159999;
.counter_src = HAL_GFXTIM_CLKGEN_LINE_COUNT_GFXTIMHCLK;
.clock_src = HAL_GFXTIM_CLKGEN_LINE_FCNT_UNDERFLOW;
};
hal_gfxtim_clkgen_frame_config_t p_frame_config = {
.reload_src = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val = 0xFU;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_DISABLE;
.clock_src = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
};
HAL_GFXTIM_CLKGEN_SetConfigFrameClock(&hgfxtim,
&p_frame_config,
&p_line_config);
/* Watchdog timer configuration */
hal_gfxtim_wdg_config_t p_wdg_config;
p_wdg_config.src = HAL_GFXTIM_WDG_CLK_LINE_CLK;
HAL_GFXTIM_WDG_SetConfig(&hgfxtim, &p_wdg_config);
/* Start the watchdog timer */
HAL_GFXTIM_WDG_Start(&hgfxtim,
1000U,
500U,
HAL_GFXTIM_WDG_ALL_IT);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_WDG_IRQHandler(&hgfxtim);
/* Watchdog alarm callback function */
USER_GFXTIM_WatchdogTimer_AlarmCallback(&hgfxtim);
/* Watchdog pre alarm callback function */
USER_GFXTIM_WatchdogTimer_PreAlarmCallback(&hgfxtim);
/* optional */
/* Refresh the watchdog timer */
HAL_GFXTIM_WatchdogTimer_Refresh(&hgfxtim);
/* Disable the watchdog timer */
HAL_GFXTIM_WDG_Stop(&hgfxtim);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
Key changes ¶
In HAL2, watchdog configuration and start are separated into dedicated
HAL_GFXTIM_WDG_SetConfig()andHAL_GFXTIM_WDG_Start()APIs.HAL2 provides dedicated IRQ handling and callback registration APIs for watchdog alarm and pre-alarm events.

